`
https://leetcode.cn/problems/letter-combinations-of-a-phone-number/
`

/**
 * @param {string} digits
 * @return {string[]}
 */
var letterCombinations = function (digits) {
  // 每个数字到字母的映射
  const mapping = [
    "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"
  ]

  const res = []
  const track = []

  // 没有输入，直接返回空数组
  if (digits === '') return res

  function backtrack(start) {
    // 到达叶子节点，找到一个答案
    if (start === digits.length) {
      return res.push(track.join(''))
    }

    // 获取当前数字
    const digit = digits[start]
    // 遍历当前数字对应的字母
    for (const c of mapping[digit].split('')) {
      track.push(c)
      // 进入下一层
      backtrack(start + 1)
      track.pop()
    }
  }

  backtrack(0)
  return res
};

// test
console.log(letterCombinations("23")) // ["ad","ae","af","bd","be","bf","cd","ce","cf"]